function[Q1, R1] =QR_factor(A)
%compute the simplified QR decomposition by gram-schmit approach
[m,n] = size(A);
Q1 = zeros(m, n);
R1 = zeros(n, n);
R1(1,1)=norm(A(:,1),2);
Q1(:,1)=A(:,1)/R1(1,1);
for k = 2:n
    R1(1:k-1, k) = Q1(1:m,1:k-1)' * A(1:m, k);
    z=A(1:m, k) - Q1(1:m,1:k-1)*R1(1:k-1, k);
    R1(k, k) = norm(z,2);
    Q1(1:m, k) = z / norm(z,2);
end
